package pers.liyan.shi.springcloud.service.fallback;

import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import pers.liyan.shi.springcloud.domain.Dept;
import pers.liyan.shi.springcloud.service.DeptClientService;

import java.util.Collections;
import java.util.List;


/**
 * 客户端服务降级 histrix断路器
 * @author shily
 * @date 2019/5/23 15:23
 */
//一定要加
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public List<Dept> getAll() {
                return Collections.EMPTY_LIST;
            }

            @Override
            public Dept getByDeptNo(Long deptNo) {
                return new Dept().setDeptName("部门微服务暂时不可用");
            }

            @Override
            public Dept addDept(Dept dept) {
                return null;
            }

            @Override
            public Dept updateDept(Dept dept) {
                return null;
            }

            @Override
            public int deleteByDeptNo(Long deptNo) {
                return -1;
            }
        };
    }
}
